package cn.kaguyaever.dao.impl;

import cn.kaguyaever.dao.JudgeDao;
import cn.kaguyaever.entity.Judge;

import java.util.List;

public class JudgeDaoImpl extends BaseDao<Judge> implements JudgeDao {

    public int createJudge(Judge judge){
        String sql = "insert into judge(`judgeId`,`judgename`,`judgepassword`,`status`,`projectId`) values(?,?,?,?,?)";
        return update(sql,judge.getJudgeId(),judge.getJudgename(),judge.getJudgepassword(),judge.getStatus(),judge.getProjectId());
    }

    public Judge queryJudgeByJudgenameAndPassword(String name,String password,String projectId){
        String sql = "select `judgeId`,`judgename`,`judgepassword`,`status`,`projectId` from judge where judgename = ? and judgepassword = ? and projectId = ?";
        return queryForOne(sql,name,password,projectId);
    }

    public List<Judge> queryAllJudgeByProjectId(String projectId){
        String sql = "select `judgeId`,`judgename`,`judgepassword`,`status`,`projectId` from judge where projectId = ?";
        return queryForList(sql,projectId);
    }

    public Judge queryJudgeByJudgeId(Integer judgeId){
        String sql = "select `judgeId`,`judgename`,`judgepassword`,`status`,`projectId` from judge where judgeId = ?";
        return queryForOne(sql,judgeId);
    }

    public Judge queryJudgeByJudgename(String name,String projectId){
        String sql = "select `judgeId`,`judgename`,`judgepassword`,`status`,`projectId` from judge where judgename = ? and projectId = ?";
        return queryForOne(sql,name,projectId);
    }

    public int setStatus(Integer judgeId){
        String sql = "update judge set status = 0 where judgeId = ?";
        return update(sql,judgeId);
    }

    public int clearStatus(String projectId){
        String sql = "update judge set status = 1 where projectId = ?";
        return update(sql,projectId);
    }

    public int votedJudge(Integer judgeId){
        String sql = "update judge set status = 1 where judgeId = ?";
        return update(sql,judgeId);
    }

    public int deleteJudge(Integer judgeId){
        String sql = "delete from judge where judgeId = ?";
        return update(sql,judgeId);
    }

    public int deleteAllJudge(String projectId){
        String sql = "delete from judge where projectId = ?";
        return update(sql,projectId);
    }
}
